package com.yang.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

//响应帮助类
public class RespUtil {
    //发送json
    public static void sendJSON(HttpServletResponse resp,Object data) throws IOException {
        resp.setContentType("text/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Gson g=new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        String msg=g.toJson(data);
        out.write(msg);
        out.flush();
        out.close();
    }

}
